﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using MyWCF.Demo.Client.Web.Code;

namespace MyWCF.Demo.Client.Web
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class EnterChatRoom : HttpHandlerBase,IHttpHandler
    {
        public static Random random = new Random();
        public void ProcessRequest(HttpContext context)
        {
            base.Init(context);

            long chatRoomId = 0;
            ChatRoomUsersEntity user = new ChatRoomUsersEntity();
            if (long.TryParse(Request.Form["ChatRoomId"], out chatRoomId)
                && string.IsNullOrEmpty(Request.Form["UserName"]) == false)
            {
                user.UserName = Request.Form["UserName"];
                user.ChatRoomId = chatRoomId;
                user.UserId = random.Next(1, 10000);
                user.ReadOnly = (byte)(user.UserId % 2 == 0 ? 1 : 0);

                ChatRoomManager.AddUserIntoChatRoom(user);
            }
            SerializeDataToResponseStream(user);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
